<?php
// 矩形的类
class Rect extends Shape {
    private $width;
    private $height;

    function __construct($array=array()) {

        if(!empty($array)) {
            $this -> width = $array['width'];
            $this -> height = $array['height'];
        }
         $this -> name = "矩形";
    }

    function area() {
        return $this->width*$this->height;
    }
    function girth() {
        return 2*($this->width+$this->height);
    }
    function window() {
        $form = '<form action="main.php?action=rect" method="post">';
        $form .= $this -> name.'的宽是：<input type="text" name="width" value="'.$_POST['width'].'" /><br />';
        $form .= $this -> name.'的长是：<input type="text" name="height" value="'.$_POST['height'].'"/><br />';
        $form .= '<input type="submit" name="dosubmit" value="计算"/><br />';
        $form .= '</form>';
        echo $form;
    }
    function verify($array) {
        $flag = true;
		if(!$array['width'] || $array['width'] < 0) {
			echo $this->name."的宽不能小于0!<br>";
			$flag = false;
		}

		if(!$array['height'] ||$array['height'] < 0) {
			echo $this->name."的高度不能小于0!<br>";
			$flag = false;
		}

		return $flag;
    }
}
